package com.briup.web.servlet;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Set;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.briup.bean.Report;

/**
 * Servlet implementation class reportDetailSer
 */
@WebServlet("/reportDetailSer")
public class reportDetailSer extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String id=request.getParameter("id");
		ServletContext sc=request.getServletContext();
		Set<Report> set=(Set<Report>)sc.getAttribute("reports");
		for(Report s:set) {
			System.out.println(s.getContent());
		}
		Report report=null;
		long idd=Long.parseLong(id);
		for(Report r:set) {
			if(r.getId()==idd) {
				report=r;
				SimpleDateFormat f=new SimpleDateFormat("yyyy.MM.dd");
				Date date=new Date();
				String publish_date=f.format(date);
				request.setAttribute("date",publish_date);
			}
		}
		request.setAttribute("report", report);
		request.getRequestDispatcher("/detail.jsp").forward(request, response);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
